package com.xxl.javaWork_15;

/**
 * @Author: xiaxinlin
 * @Date: 2020/12/15 17:13
 */
public class Demo {
    public static void main(String[] args) {
//        RunDemo runDemo = new RunDemo();
//        Thread thread = new Thread(runDemo);
//        Thread thread1 = new Thread(runDemo);
//        thread.start();
//        thread1.start();
        ThreadDemo threadDemo = new ThreadDemo();
        ThreadDemo threadDemo1 = new ThreadDemo();
        threadDemo.start();
        threadDemo1.start();
    }
}
class RunDemo implements Runnable{
    private int number=0;

    @Override
    public void run() {
        for (int i=0;i<100;i++){
            testRun();
        }
    }

    public synchronized void testRun(){
        number++;
        System.out.println(number);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
class ThreadDemo extends Thread{
    private static int number=0;
    @Override
    public void run() {
        super.run();
        for (int i=0;i<100;i++){
            testRun();
        }
    }

    public static synchronized void testRun(){
        number++;
        System.out.println(number);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
